//
//  LXDTabBarViewController.m
//  lxd-inke
//
//  Created by ma c on 16/9/1.
//  Copyright © 2016年 lxd. All rights reserved.
//

#import "LXDTabBarViewController.h"
#import "LXDTabBar.h"
#import "LXDBaseNavViewController.h"
#import "LXDLaunchViewController.h"
@interface LXDTabBarViewController ()<LXDTabBarDelegate>
@property (nonatomic, strong) LXDTabBar * lxdTabBar;
@end

@implementation LXDTabBarViewController

- (void)tabbar:(LXDTabBar *)tabbar clickButton:(LXDItemType)idx {

    if (idx != LXDItemTypeLaunch) {
        self.selectedIndex = idx - LXDItemTypeLive;
        return;
    }
    LXDLaunchViewController * LaunchVC = [[LXDLaunchViewController alloc] init];
    [self presentViewController:LaunchVC animated:YES completion:nil];
    
}

- (LXDTabBar *)lxdTabBar {

    if (!_lxdTabBar) {
        _lxdTabBar = [[LXDTabBar alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 49)];
        _lxdTabBar.delegate = self;
    }
    return _lxdTabBar;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // 加载控制器
    [self configViewControllers];
    
    // 加载tabbar
    [self.tabBar addSubview:self.lxdTabBar];
    // 消除Tabbar的阴影线
    [[UITabBar appearance] setShadowImage:[UIImage new]];
    [[UITabBar appearance] setBackgroundImage:[UIImage new]];
}

- (void)configViewControllers {

    NSMutableArray * mutArray = [NSMutableArray arrayWithArray:@[@"LXDMainViewController",@"LXDMeViewController"]];
    
    for (NSInteger i = 0; i < mutArray.count; i++) {
        
        NSString * vcName = mutArray[i];
        
        UIViewController * vc = [[NSClassFromString(vcName) alloc] init];
        
        LXDBaseNavViewController * nav = [[LXDBaseNavViewController alloc] initWithRootViewController:vc];
        
        [mutArray replaceObjectAtIndex:i withObject:nav];
        
    }
    self.viewControllers = mutArray;
}

@end
